from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData
from mall.mall import settings

def generate_openid_token(openid):

    serializer=Serializer(settings.SECRET_KEY,expires_in=3600)

    data={'openid':openid}
    token=serializer.dumps(data)

    return token.decode()


def check_access_token(token):
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)
    try:
        data=serializer.loads(token)

    except BadData:
        return None
    return data['openid']
